<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<html>
<head>
<title></title>
<link href="<s:url value='/common/lib/ligerUI/skins/Aqua/css/ligerui-all.css'/>" rel="stylesheet" type="text/css" />
<script src="<s:url value='/common/lib/jquery/jquery-1.3.2.min.js'/>" type="text/javascript"></script>
<script src="<s:url value='/common/lib/ligerUI/js/core/base.js'/>" type="text/javascript"></script> 
<script src="<s:url value='/common/lib/ligerUI/js/plugins/ligerDialog.js'/>" type="text/javascript"></script>
<script type="text/javascript">
	var errorMsgTitle = "<s:text name='dialog.title.error'/>";
	$(function() {
		$("#msg").hide();
	});
	function uploadFile() {
		var fileName = $("#originalFile").val();
		if(fileName == "") {
			$.ligerDialog.alert("请选择原始清单", errorMsgTitle, "error");
			return false;
		}
		$.ligerDialog.confirm('请确定确定原始数据格式是否正确', function (yes) {
			if(yes) {
				var suffix = fileName.substr(fileName.lastIndexOf('.') + 1).toLowerCase();
				if(suffix != "xls" && suffix != "xlsx") {
					$.ligerDialog.alert("原始清单格式不正确，请上传excel文件", errorMsgTitle, "error");
					return false;
				}
				var index = fileName.lastIndexOf("\\");
				if(index > 0) {
					fileName = fileName.substr(index);
				}
				var names = fileName.split("-");
				if(names.length != 4 || !(/^[0-9]+$/.test(names[1]))) {
					$.ligerDialog.alert("原始清单名不正确，请使用正确文件名上传\n(例如：上海大众-经销商网络代码-经销商-原始清单.xml)", errorMsgTitle, "error");
					return false;
				}
				
				$("input[type='button']").attr("disabled","disabled");
				$("input[type='text']").attr("disabled","disabled");
				$("#msg").show();
				$("#dealerCode").val(names[1]);
				$("#suffix").val(suffix);
				$("#uploadFileForm").submit();
				return true;
			} else {
				$("#textfield").val("");
			}
		});
		return false;
	}
</script>
<style type="text/css">
    .l-table-edit {}
    .l-table-edit-td{padding:4px;}
    .l-button-submit,.l-button-reset{width:80px; float:left; margin-left:10px; padding-bottom:2px;}
    .file-box{position:relative;width:500px;padding: 5px;} 
	.txt{height:22px; border:1px solid #cdcdcd; width:180px;} 
	.btn{background-color:#FFF; border:1px solid #CDCDCD;height:24px; width:120px;} 
	.file{position:absolute; right:205px; top:0; height:24px; filter:alpha(opacity:0); opacity:0;}
    .errors {
		background-color:#FFCCCC;
		border:1px solid #CC0000;
		width:800px;
		margin-bottom:8px;
	}
	.errors li{ 
		list-style: none; 
	}
	.message {
		background-color:#AECAF0;
		border:1px solid #CC0000;
		width:400px;
		margin-bottom:8px;
	}
	.message li{ 
		list-style: none; 
	}
</style>
</head>
<body>
	<h3><s:text name="title.upload.original.data"/></h3>
	<s:if test="hasActionErrors()">
   			<div id="errorMsg" class="errors">
      			<s:actionerror/>
   			</div>
    </s:if>
    
    <div id="msg" class="message">
      	<p>文件上传中，请稍候 ...</p>
    </div>
    
    <div class="file-box"> 
		<form id="uploadFileForm" action="<s:url value='/record/uploadOriginalData.action'/>" method="post" enctype="multipart/form-data">
			<s:hidden name="dealerCode"/>
			<s:hidden name="suffix"/>
			<input type='text' id='textfield' name='textfield' class='txt' onclick="document.getElementById('originalFile').click()"/> 
			<input type='button' class='btn' value='选择原始清单...' onclick="document.getElementById('originalFile').click()"/> 
			<input type="file"  name="originalFile" class="file" id="originalFile" size="28" onchange="document.getElementById('textfield').value=this.value" /> 
			<input type="button" class="btn" value="上传" onclick="uploadFile()"/> 
		</form> 
	</div> 
</body> 
</html>